//
//  LocalVideoViewController.m
//  VLCPlayer
//
//  Created by mac on 2019/3/31.
//  Copyright © 2019 YangYang. All rights reserved.
//

#import "LocalVideoViewController.h"
#import "MRVLCPlayer.h"

@interface LocalVideoViewController ()

@property (nonatomic, strong) MRVLCPlayer *player;

@end

@implementation LocalVideoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createUI];
}

-(void)createUI
{
    UIButton *playAction = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:playAction];
    playAction.frame = CGRectMake(kScreenWidth / 2 - 50, 64 + 20, 100, 40);
    playAction.titleLabel.font = [UIFont systemFontOfSize:20];
    [playAction setTitle:@"播放" forState:UIControlStateNormal];
    [playAction setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [playAction addTarget:self action:@selector(playVideoAction) forControlEvents:UIControlEventTouchUpInside];
}

-(void)playVideoAction
{
    
    NSURL *mediaURL = [[NSBundle mainBundle] URLForResource:_localVideoName withExtension:nil];
    NSLog(@"mediaPath = %@",mediaURL.absoluteString);
    self.player.mediaURL = mediaURL;
    [self.player showInView:self.view.window];
}

-(MRVLCPlayer *)player
{
    if (!_player) {
        _player = [[MRVLCPlayer alloc] init];
        _player.bounds = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width / 16 * 9);
        _player.center = self.view.center;
    }
    return _player;
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [_player dismiss];
}

-(void)dealloc
{
    NSLog(@"销毁本地视频播放控制器");
//    [_player removeFromSuperview];
//    _player = nil;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
